
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.chepaandvasia.dao.CarDAO;
import com.chepaandvasia.entities.Car;
import com.chepaandvasia.entities.ServiceCheck;

public class Test {

    private static ApplicationContext context;

	//  private static ServiceRegistry ServiceRegistryBuilder;
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        Car car = new Car();
        car.setCarModel("Civik");
        car.setCarProducer("Toyota");
        car.setColour("black");
        car.setEngineType("2.0");
        car.setNumberOfKms(2000);
        car.setYearOfManufacture(2010);

        ServiceCheck serviceCheck = new ServiceCheck();
        serviceCheck.setActive(true);
        serviceCheck.setCheckInterval(100);

        ServiceCheck serviceCheck2 = new ServiceCheck();
        serviceCheck2.setActive(false);
        serviceCheck2.setCheckInterval(101);

        car.getControlServiceCheck().add(serviceCheck);
        car.getControlServiceCheck().add(serviceCheck2);

        context = new ClassPathXmlApplicationContext("applicationContext.xml");
        String[] names = context.getBeanDefinitionNames();
        for (int i = 0; i < names.length; i++) {
            String string = names[i];
            System.out.println(string);
        }

        CarDAO carDAO = (CarDAO) context.getBean("carDAO", CarDAO.class);
        carDAO.create(car);
//        Configuration configuration = new Configuration();
//        configuration.configure();
//        ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
//        SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
//    //    SessionFactory sessionFactory = new  Configuration().configure().buildSessionFactory(serviceRegistry);
//        Session session = sessionFactory.openSession();
//
//
//        session.beginTransaction();
//        session.save(car);
//        session.save(serviceCheck);
//        session.save(serviceCheck2);
//        session.getTransaction().commit();
//        session.close();

    }
}
